package easy;

public class a566_重塑矩阵 {
    public int[][] matrixReshape(int[][] mat, int r, int c) {
        if (mat.length * mat[0].length != r * c) {
                return mat;
        }
        int[][] res = new int[r][c];
        for (int i = 0; i < mat.length * mat[0].length; i++) {
            res[i/r][i%c]=mat[i/mat.length][i%mat[0].length];
        }
    return res;
    }

}
